$(document).ready(function() {	
	$('textarea#pcontent').ckeditor();
	$('#frmAdd').validate({
		errorClass		: 'error',
		errorElement	: 'span',
		onfocusout		: false,
		onkeyup			: false,
		ignore			: 'input[type="text"]:hidden',
		rules: {
			pcategoryid: {
				min						: 1
			},
			psubid: {
				min						: 1
			},
			ptitle:{
				required				: true,
				minlength				: VL_NAME_MINLENGTH
			},
			pimage: {
				required				: true,
				validateImgFormat		: true,
				validateImgSize			: true
			},	
			pflash: {
				validateFlash			: true
			},
			pshort: {
				minlength				: VL_SHORT_MINLENGTH,
				maxlength				: VL_SHORT_MAXLENGTH
			},
			pcontent: {
				validateContentRequired	: true,
				validateContentMinlength: true
			},
			plink: {
				url						: true
			}
		},
		messages: {	
			pcategoryid: {
				min						: category_required
			},
			psubid: {
				min						: sub_required
			},
			ptitle:{
				required				: name_required,
				minlength				: name_minlength
			},		
			pimage: {
				required				: image_required,
				validateImgFormat		: image_format,
				validateImgSize			: image_size
			},
			pflash: {
				validateFlash			: flash_format
			},
			pshort: {
				minlength				: short_minlength,
				maxlength				: short_maxlength
			},
			pcontent: {
				validateContentRequired	: content_required,
				validateContentMinlength: content_minlength
			},
			plink: {
				url						: link_format
			}
		},
		errorPlacement: function(label, element) {
			var id = element.attr('id');	
			if(id == 'pcontent') {			
				label.insertAfter($('#cke_pcontent'));
			} else {
				label.insertAfter($('#' + id));			
			}
			
		}				 
	});
	$.validator.addMethod('validateImgFormat', function() {
		var strLinkImage = $('#pimage').val();
		if(strLinkImage == "") {
			return false;
		}
		return validateImage(strLinkImage);
	});
	$.validator.addMethod('validateImgSize', function() {
		var strLinkImage = $('#pimage').val();
		if(strLinkImage == "") {
			return false;
		}
		return validateImgSize('pimage');
	});	
	$.validator.addMethod('validateFlash', function() {
		var strFlash = $('#pflash').val();
		if(strFlash != "")
			return validateObjectFlash(strFlash);
		return true;
	});
	$.validator.addMethod('validateContentRequired',function(){		
		var strContent		= stripTags($('#pcontent').val(), 1);		
		if(strContent == '')
			return false;		
		return true;												 
	});
	$.validator.addMethod('validateContentMinlength',function(){
		var strContent		= stripTags($('#pcontent').val(), 1);		
		if(strContent != '' && strContent.length < VL_CONTENT_MINLENGTH)
			return false;		
		return true;												 
	});	
});